package com.kamistoat.meimeistore.apisystem.factory;

import com.kamistoat.meimeistore.apisystem.domain.SysUser;
import com.kamistoat.meimeistore.apisystem.feign.RemoteUserService;
import com.kamistoat.meimeistore.apisystem.model.LoginUser;
import com.kamistoat.meimeistore.commoncore.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 文件服务降流处理
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {

    private static final Logger LOGGER = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable cause) {
        LOGGER.error("用户服务调用失败:{}", cause.getMessage());
        return new RemoteUserService() {
            @Override
            public R<LoginUser> getUserInfo(String username, String source) {
                return R.fail("用户服务调用失败:" + cause.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfoByUserId(Long userId, String source) {
                return R.fail("用户服务调用失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source) {
                return R.fail("用户服务调用失败:" + cause.getMessage());
            }
        };
    }
}
